package com.base.service.impl;

import java.util.List;

import com.base.bean.Cardmaker;
import com.base.service.CardmakerService;
import com.common.util.AbstractManager;
import com.common.util.PagerModel;

public class CardmakerServiceImpl extends AbstractManager implements
		CardmakerService {

	public void addCardmaker(Cardmaker cardmaker) {
		String hql = "select nvl(max(compno),0) from Cardmaker";
		
		long compno = 0l;
		compno = (Long) this.getHibernateTemplate().find(hql).get(0);
		compno += 1l;
		
		cardmaker.setCompno(compno);
		this.getHibernateTemplate().save(cardmaker);
	}

	@SuppressWarnings("unchecked")
	public List<Cardmaker> findAllCardmaker() {
		String hql = "from Cardmaker order by compno";
		return this.getHibernateTemplate().find(hql);
	}

	public Cardmaker findCardmaker(long compno) {
		return (Cardmaker) this.getHibernateTemplate().load(Cardmaker.class, compno);
	}

	public PagerModel findCardmakerForPager() {
		String hql = "from Cardmaker order by compno";
		return searchPaginated(hql);
	}

	public void removeCardmaker(long compno) {
		Cardmaker cardmaker = null;
		cardmaker = (Cardmaker) this.getHibernateTemplate().load(Cardmaker.class, compno);
		if(cardmaker != null) 
			this.getHibernateTemplate().delete(cardmaker);
	}

	public void updateCardmaker(Cardmaker cardmaker) {
		this.getHibernateTemplate().update(cardmaker);
	}

}
